package cn.buk.qms.service;

import cn.buk.common.JsonResult;
import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.dto.SettlementDto;
import cn.buk.tms.dto.SettlementReportDto;
import cn.buk.tms.sc.SearchBillInfoCriteria;
import cn.buk.tms.sc.SearchFlightOrderCriteria;
import cn.buk.tms.sc.SearchSettlementCriteria;
import cn.buk.tms.entity.base.Airport;
import cn.buk.tms.entity.bill.*;
import cn.buk.tms.entity.misc.Customer;
import cn.buk.tms.entity.misc.OperationLog;
import cn.buk.tms.entity.bill.SettlementSheet;

import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

/**
 * 账单管理
 *
 * @author yfdai
 * @date 2017/7/17
 */
public interface BillService {

  List<BillInfo> searchMyBillInfo(int enterpriseId, SearchBillInfoCriteria sc, int customerId);

  List<BillInfo> searchMyBillInfo(int enterpriseId, SearchBillInfoCriteria sc, int customerId, boolean getDetail);

  /**
   * 根据订单号查找对应的账单
   */
  List<BillInfo> searchBillInfoByOrderNo(int enterpriseId, String orderNo);

  /**
   * 获取账单详情（通过账单id或账单号)
   */
  BillInfo searchBillInfoDetail(int enterpriseId, int id, String billNum);

  double searchBillSum(int enterpriseId, String billNum);

  void addBillFlightTickets(BillInfo info);

  JsonResult createTrainTicket(int enterpriseId, String operator, int customerEnterpriseId, int supplierId, int paymentId, BillTrainTicket trainTicket);

  List<BillTrainTicket> searchTrainTickets(int enterpriseId, SearchBillInfoCriteria sc);

  JsonResult createHotelBooking(int enterpriseId, String operator, int customerEnterpriseId, int supplierId, int paymentId, BillHotelBooking hotelBooking);

  List<BillHotelBooking> searchHotelBookings(int enterpriseId, SearchBillInfoCriteria sc);






  /**
   * 查找未审核的账单的机票
   *
   * @param enterpriseId 企业id
   * @param sc           查找条件
   * @return 符合的账单票号
   */
  List<BillFlightTicket> searchUnreviewedFlightTickets(int enterpriseId, SearchFlightOrderCriteria sc);

  List<BillFlightTicket> searchUnpaidFlightTickets(int enterpriseId, SearchFlightOrderCriteria sc);

  JsonResult deleteBillInfo(int enterpriseId, String username, int id);

  /**
   * 审核账单通过
   */
  JsonResult auditBillInfoDone(int enterpriseId, String operator, int id);

  JsonResult auditBillInfoDoneByBillNum(int enterpriseId, String operator, String billNum);

  /**
   * 取消账单审核
   */
  JsonResult cancelBillInfoAuditPassed(int enterpriseId, String operator, int id, String remark);

  BillFlightTicket searchFlightTicket(int enterpriseId, String ticketNo);

  JsonResult createFlightRefundTicket(int enterpriseId, String ticketNo, String psgName, double accountRecv, double airRefundFee, double serviceCharge, String remark, String operator);

  List<BillFlightRefundTicket> searchFlightRefundTickets(int enterpriseId, CommonSearchCriteria sc);


  JsonResult changeBillCustomer(int enterpriseId, String username, int billId, int customerId, String costCenter, String projectName);



  /**
   * 批量审核账单
   *
   * @param enterpriseId 企业id
   * @param username     用户名
   * @param billIds      准备审核的账单id列表
   * @param total        准备审核的账单的金额总和
   * @return 操作结果
   */
  JsonResult batchReviewBillInfos(int enterpriseId, String username, int[] billIds, double total);

  /**
   * 创建或加入结算单
   */
  JsonResult createSettlement(int enterpriseId, String username, int customerId, int settlementId, String settlementNo, String settlementName, double total, Integer[] billIds);

  /**
   * 批量创建结算单
   */
  JsonResult batchCreateSettlement(int enterpriseId, String username, Date beginDate, Date endDate, int customerId, String prefix);

  /**
   * 查找结算单
   *
   * @param enterpriseId 企业id
   * @param sc           查找条件
   * @return 结算单列表
   */
  List<SettlementSheet> searchSettlements(int enterpriseId, int userId, SearchSettlementCriteria sc);


  List<SettlementSheet> searchUnpaidSettlements(int enterpriseId, int customerId);

  /**
   * 从结算单中移除一个账单
   */
  JsonResult removeBillOfSettlement(int enterpriseId, String username, int settlementId, String billNo);

  List<OperationLog> searchSettlementHistory(int enterpriseId, int settlementId);

  List<OperationLog> searchBillInfoHistory(int enterpriseId, int id);

  JsonResult updateBillInfoSupplier(int enterpriseId, String username, int billId, int supplierId);

  JsonResult updateBillInfoPayment(int enterpriseId, String username, int billId, int payId);

  JsonResult updateBillInfoEtdzDate(int enterpriseId, String username, int billId, Date etdzDate);

  /**
   * 修改账单日期
   */
  JsonResult updateBillInfoOpDate(int enterpriseId, String username, int billId, Date opDate);

  /**
   * 修改账单中的预订人
   */
  JsonResult updateBillInfoOp1(int enterpriseId, String username, int billId, String op1);

  JsonResult updateBillInfoRemark(int enterpriseId, String username, int billId, String remark);

  /**
   * 修改付款类型
   */
  JsonResult updateBillInfoPayType(int enterpriseId, String username, int billId, String payType);


  JsonResult autoReviewBillInfo(int enterpriseId, String username);

  /**
   * 系统任务执行自动审核
   */
  JsonResult autoReviewBillInfoByTask(int enterpriseId, String username);





  /**
   * 在结算单中查找账单
   *
   * @param enterpriseId  企业id
   * @param id            结算单id
   * @param billNo        账单号
   * @param orderNo       订单号
   * @param billDate      账单日期
   * @param flightOrderNo 原机票订单号
   * @param psgName       客人姓名
   */
  List<BillInfo> searchSettlementBills(int enterpriseId, int id, String billNo, String orderNo,
                                       String billDate, String flightOrderNo, String psgName);

  /**
   * 把账单从结算单中移除
   *
   * @param enterpriseId 企业id
   * @param username     用户名
   * @param id           账单id
   * @return 是否成功
   */
  JsonResult deleteSettlementNo(int enterpriseId, String username, int id);

  JsonResult adjustSettlementAmount(int enterpriseId, int userId, String username, int id, double amount, String remark);

  List<BillFlightTicket> searchSettlementBillFlightTicket(int enterpriseId, int id, String psgName, String ticketNo);

  List<BillFlightRefundTicket> searchSettlementRefunds(int enterpriseId, int id);

  List<BillChangeOrder> searchSettlementChanges(int enterpriseId, int id);

  List<BillVasOrder> searchSettlementVases(int enterpriseId, int id);

  List<BillHotelBooking> searchSettlementHotels(int enterpriseId, int id);

  List<BillTrainTicket> searchSettlementTrains(int enterpriseId, int id);

  List<BillRentalCarOrder> searchSettlementBillRentalCars(int enterpriseId, int id);

  JsonResult updateSettlementName(int enterpriseId, String username, int id, String settlementName);

  /**
   * 结算单明细
   *
   * @param enterpriseId 企业id
   * @param id           结算单id
   * @return 结算单dto对象
   */
  SettlementDto searchSettlementDetail(int enterpriseId, int id);

  /**
   * 结算单的报表格式
   */
  SettlementReportDto searchSettlementReport(int enterpriseId, int id);

  void updateBillRefundTicketPnrNo(String agentName);

  /**
   * 自动更新服务账单中相关的信息
   */
  void autoUpdateBillVas(String agentName);

  /**
   * 超级管理员对账单进行销账
   */
  JsonResult writeOffBill(int enterpriseId, int userId, int id);

  /**
   * 修改账单支付状态
   */
  JsonResult updateBillPaymentStatus(int enterpriseId, int userId, int id, int paymentStatus);

  /**
   * 自动预审昨日的BSP账单
   */
  void autoPreviewBills(int enterpriseId, String username, Date billDate, int supplierBspType);

  /**
   * 使用默认格式导出账单内容
   */
  void exportDefaultFormatBills(SearchBillInfoCriteria sc, int format, int enterpriseId, int customerId, List<Airport> airports, List<Customer> customers, PrintWriter out);

  void prepareSettlementReportTpl3(SettlementReportDto dto);

  /**
   * 分离机票账单的票号
   *
   * @param enterpriseId 企业id
   * @param username     用户名id
   * @param billId       账单id
   * @param ticketId     票号id
   */
  JsonResult splitFlightBill(int enterpriseId, String username, int billId, int ticketId);

  JsonResult splitVasBill(int enterpriseId, String username, int billId, int orderId, int psgId);

  /**
   * 将结算单中的所有账单移除
   *
   * @param settlementId 结算单id
   */
  JsonResult removeAllBillsFromSettlement(int enterpriseId, String username, int settlementId);
}
